#!/bin/bash


DIR="tmp/20250202/F24-21201-23-01-MCI--aging-test-96hrs"

if [ -d ${DIR} ]; then
    echo "> ${DIR} already exist."
else
    mkdir -p ${DIR}
fi

LOG_FILE="${DIR}/auto_dark_bias.log"

if [ -f ${LOG_FILE} ];then
    echo "--> ${LOG_FILE} exits."
else
    touch ${LOG_FILE}
fi

echo "# START of BIAS-FIELD LOG" >> ${LOG_FILE}
echo $(date) >> ${LOG_FILE}

# 曝光命令
CMD_EXPOSURE='./exposure'

# 保存DDR中数据到本地（行数、列数需要与CCD读出时序相匹配）
N_ROW=4700
N_COL=1250
N_BYTES=2
FAST_MODE=1


N_MIN=0
N_MAX=2000


n=${N_MIN}
m=1
while [ ${n} -le ${N_MAX} ]
do
    div_val=$[ ${n} % 10 ]
    FOUT_FNAME=${DIR}/tmp.bin
    bin/ccd290_readout -b ${N_BYTES} -r ${N_ROW} -c ${N_COL} -f ${FAST_MODE} -o ${FOUT_FNAME}
    
    if [ $div_val -eq 0 ]; then
        FOUT_FNAME=${DIR}/bias_${m}.bin    
	    m=$[ ${m} + 1 ]
        bin/ccd290_readout -b ${N_BYTES} -r ${N_ROW} -c ${N_COL} -f ${FAST_MODE} -o ${FOUT_FNAME}
        echo `date` >> ${LOG_FILE}
    fi
	
	n=$[ ${n} + 1 ]
	sleep 150
done

echo "# END of BIAS-FIELD LOG" >> ${LOG_FILE}

